package com.tianqu.tms.www.car.controller;

import java.util.ArrayList;
import java.util.List;
import com.tianqu.tms.core.base.Logger;
import com.tianqu.tms.core.base.TmsController;
import com.tianqu.tms.core.base.TxController;
import com.tianqu.tms.core.base.UserContext;
import com.tianqu.tms.core.exception.TmsException;
import com.tianqu.tms.core.exception.TransactionException;
import com.tianqu.tms.core.util.TmsConstants;
import com.tianqu.tms.entity.MarketCarInfoTemp;
import com.tianqu.tms.www.car.action.CarInformationCollectListAction;
/**
 * @author mufeiyu
 * 车辆采集列表controller
 */
public class CarInformationCollectListController extends TmsController{
	private Logger logger = Logger.getLogger(CarInformationCollectListController.class);
	public static final String PAGING = "paging";
	@Override
	public void execute(UserContext uc) throws Exception {
		logger.debug(this.getClass().getName() + "#execute was called.");
		TxController controller = TxController.getTxController();

		// 添加事务提交异常捕获
		try {
			controller.begin();
			MarketCarInfoTemp carInfoTemp = MarketCarInfoTemp.getInstance();

			if (uc.getAttribute(CarInformationCollectListAction.PAGENO) != null) {
				carInfoTemp.setPageNo(Integer.parseInt((String) uc
						.getAttribute(CarInformationCollectListAction.PAGENO)));
			}
			if (uc.getAttribute(CarInformationCollectListAction.MAXINDEX) != null) {
				carInfoTemp.setMaxIndex(Integer.parseInt((String) uc
						.getAttribute(CarInformationCollectListAction.MAXINDEX)));
			}
			if (uc.getAttribute(CarInformationCollectListAction.SORTKEY) != null) {
				carInfoTemp.setSortKey(Integer.parseInt((String) uc
						.getAttribute(CarInformationCollectListAction.SORTKEY)));
			}
			if (uc.getAttribute(CarInformationCollectListAction.ASC) != null) {
				carInfoTemp.setAsc((new Boolean((String) uc
						.getAttribute(CarInformationCollectListAction.ASC)))
						.booleanValue());
			}
			List list = new ArrayList();
			list = carInfoTemp.loadPadHistory();
			uc.setAttribute(TmsConstants.VIEWHELP, list);
			uc.setAttribute(PAGING, carInfoTemp);
			
			controller.commit();
		} catch (Exception e) {
			try {
				controller.rollback();
			} catch (TransactionException e1) {
				throw new TmsException(TmsException.DB_TXCRROR, e1);
			}
			// 系统异常
			if (e instanceof TmsException) {
				throw e;
			}
			throw new TmsException(TmsException.DB_TXCRROR, e);
		}

		logger.debug(this.getClass().getName() + "#execute was completed.");
		
	}

}
